const fs=require('fs');
const util=require('util')


const os=require('os')
const pfs=fs.promises
const path=require('path');


const str="你!!!"+os.EOL;
// console.log(Buffer.from(str))


//异步
// fs.writeFile(path.resolve('data/a.txt'),Buffer.from(str),err=>console.log(err))
// fs.writeFile(path.resolve('data/a.txt'),str,err=>console.log(err))


//同步
// try{
//     fs.writeFileSync(path.resolve('./data/a.txt'),str)
// }catch (e){}

// fs.writeFile(path.resolve('./data/a.txt'),str,{
//     encoding:'utf-8',
//     flag:'a'
// },err=>console.log(err))
// fs.appendFile(path.resolve('data/a.txt'),str,e=>console.log(e))

let  filepath =path.resolve('data/a.txt');
let  newfilepath=path.resolve('data/b.txt')
// fs.readFile(filepath,(err,buffer)=>{
//     console.log(buffer.toString());
// })

// fs.readFile(filepath,'utf-8',(err,data)=>{
//     console.log(data);
// })

//同步
// let data=fs.readFileSync(filepath,'utf-8')
// console.log(data)


//  fs.readFile(filepath, 'utf-8', (err, data) => {
//   fs.writeFile(newfilepath, data, err => console.log(err))
// })

// readFile(filepath).then(data=>console.log(data.toString()))

// readFile(filepath).then(data=>console.log(data))

// ;(async function(){
//     let data=await readFile(filepath)
//     console.log(data);
// })()


//数据流
// pfs.createReadStream(filepath).pipe(fs.createWriteStream(newfilepath))


//删除文件
// fs.unlink(newfilepath,err=>console.log(err))


//查看文件信息
// fs.stat(filepath,(err,stat)=>{
//     console.log(stat.isFile());
//     console.log(stat.isDirectory());
// })


const dirpath=path.join(__dirname,'data','damin')
// fs.mkdir(dirpath,err=>console.log(err))

//迭代创建
// fs.mkdir(dirpath,{recursive:true},err=>console.log(err))

fs.rmdir(dirpath,err=>console.log(err))